
var base_num = 0;
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.globalData.imgurl,
    showshare:false,
     //商品列表标签
    tabs: [{ name: "商品", nav_selected: 'nav_selected' }, 
    //{ name: "评价", nav_selected: '' }, { name: "商家", nav_selected: '' }
    ],   
    showCart: true,    //底部购物车
    category: [  // 左侧选项卡
      // { name: "商品1", cate_selected: 'cate_selected' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' }
    ],
    goods:[
    // {
    //   id:12,
    //   name:'商品',
    //   picUrl:'/img/goodimg_03.png',
    //   price:'2550/天',
    //   }, {
    //     id: 12,
    //     name: '商品',
    //     picUrl: '/img/goodimg_03.png',
    //     price: '2550/天',
    //   },
    ],
  },
  onLoad: function (options) {
    var that = this;
    // 渲染店铺信息     
    this.setBaseInfo(options)
    // 商品列表
    // this.getGoodsList(options)
    this.setData({
      shopid: options.shopid,
    })
  },
  onShow: function () {

  },
  // 渲染店铺信息
  setBaseInfo: function (options) {
    console.log(options)
    var that = this;
    wx.showLoading({
      title: '正在加载',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'shop_xq?sh_id=' + options.shopid,
      success: function (res) {
        var data = res.data[0];
        var cate = data.cate
        cate[0].cate_selected = 'cate_selected'
        console.log(data)
        that.setData({
          data: data,
          cate: cate,
          goods: cate[0].product
        })
      },
      complete(){
        wx.hideLoading()
      }
    })
    
  },
  navTabClick: function (e) {
    var o = e.currentTarget.dataset
    var tabs = this.data.tabs
    for (var i = 0; i < tabs.length; i++) {
      tabs[i].nav_selected = ''
    }
    tabs[o.index].nav_selected = 'nav_selected'
    this.setData({
      current: o.index
    });
  },
  // 选择分类
  selectCate(e){
    var o = e.currentTarget.dataset
    var cate = this.data.cate
    for(var i = 0; i < cate.length; i++){
      cate[i].cate_selected = ''
    }
    cate[o.index].cate_selected = 'cate_selected'
    this.setData({
      cate: cate,
      goods:cate[o.index].product
    })
  },
  goodDetail:function(e){
    var o = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/list/detail/detail?id='+o.id,
    })
  },
  //点击商家头部信息进入商家详情信息
  shopdetail: function (e) {
    var o = e.currentTarget.dataset

    wx.showLoading({
      title: '加载中...',
    })
    wx.navigateTo({
      url: '/pages/list/detail/shopdetail?shopid=' + o.shopid,
      success: function () {
        wx.hideLoading()
      }
    })
  },
})